home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1995 March / PC Plus Super CD (Issue 101) (March 1995).iso / tclite / include / timec.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-27  |  3.0 KB  |  69 lines

  1. #ifndef TIMEC_H
  2. #define TIMEC_H
  3.  
  4. #include "object.h"
  5.  
  6. typedef unsigned int hourTy;
  7. typedef unsigned int minuteTy;
  8. typedef unsigned int secondTy;
  9. typedef unsigned long clockTy;
  10.  
  11. extern const Class class_Time;
  12. class Date;
  13.  
  14. class Time: public Object {
  15.     clockTy     sec;                        // seconds since 1/1/1901
  16.     bool        isDST() const;
  17.     Time        localTime() const;
  18. public:
  19.     ////////////////////////////////////////////////////////
  20.     ////////////////////  constructors  ////////////////////
  21.     ////////////////////////////////////////////////////////
  22. Time(const Time& time) { sec=time.sec; }
  23.             Time();                         // current time
  24.             Time(clockTy s)                 { sec = s; }
  25.             Time(hourTy h, minuteTy m, secondTy s =0, bool dst =NO);
  26.             Time(const Date&,   hourTy h =0,
  27.                  minuteTy m =0, secondTy s=0, bool dst =NO);
  28.  
  29.     Date    getDate() const;
  30.     void    update();
  31.     bool    operator<(Time time)    const   { return sec < time.sec; }
  32.     bool    operator<=(Time time)   const   { return sec <= time.sec; }
  33.     bool    operator>(Time time)    const   { return sec > time.sec; }
  34.     bool    operator>=(Time time)   const   { return sec >= time.sec; }
  35.     bool    operator==(Time time)   const   { return sec == time.sec; }
  36.     bool    operator!=(Time time)   const   { return sec != time.sec; }
  37.  
  38.     friend Time operator+(Time t, long s) const { return Time(t.sec+s); }
  39.     friend Time operator+(long s, Time t) const { return Time(t.sec+s); }
  40.  
  41.     long    operator-(Time t)       const   { return sec - t.sec; }
  42.     Time    operator-(long s)       const   { return Time(sec-s); }
  43.     void    operator+=(long s)              { sec += s; }
  44.     void    operator-=(long s)              { sec -= s; }
  45.     bool    between(Time a, Time b) const   {
  46.                                               return
  47.                                               *this >= a && *this <= b;
  48.                                             }
  49.     hourTy  hour()                  const;  // hour in local time
  50.     hourTy  hourGMT()               const;  // hour in GMT
  51.    minuteTy minute()                const;  // minute in local time
  52.    minuteTy minuteGMT()             const;  // minute in GMT
  53.    secondTy second()                const;  // second in local time or GMT
  54.     clockTy seconds()               const   { return sec; }
  55.     Time    max(Time)               const;
  56.     Time    min(Time)               const;
  57.  
  58.     virtual int             compare(const Object&)  const;
  59.     virtual Object*         copy()                  const;
  60.     virtual void            deepenShallowCopy();
  61.     virtual unsigned        hash()                  const;
  62.     virtual const Class*    isA()                   const;
  63.     virtual bool            isEqual(const Object&)  const;
  64.     virtual void            printOn(ostream& strm)  const;
  65.     virtual const Class*    species()               const;
  66. };
  67.  
  68. #endif
  69.